#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int sex, count;
    string name;
    vector<int> sexs;
    vector<string> names;
    cin >> count;
    for (int i = 0;i < count;i++)
    {
        cin >> sex >> name;
        sexs.push_back(sex);
        names.push_back(name);
    }
    while (sexs.size())
    {
        int st = 0;
        int ed = sexs.size()-1;
        while (ed)
        {
            if (sexs[st] != sexs[ed])
            {
                cout << names[st] << ' ' << names[ed] << endl;
                names.erase(names.begin());
                sexs.erase(sexs.begin());
                ed--;
                names.erase(names.begin() + ed);
                sexs.erase(sexs.begin() + ed);
                break;
            }
            ed--;
        }
    }
    return 0;
}
